# -*- coding: utf-8 -*-
# @File: backend => gameplay_schema.py
# @CreateTime: 2025/8/28 11:27
# @Author: EvanZhang
# @Info: 游戏相关的Pydantic模型

from pydantic import BaseModel, Field
from typing import Optional, List, Dict
from datetime import datetime

class StartGameRequest(BaseModel):
    """开始游戏请求"""
    pass

class StartGameResponse(BaseModel):
    """开始游戏响应"""
    hand_id: int = Field(..., description="牌局ID")
    message: str = Field(..., description="响应消息")

class PlayerActionRequest(BaseModel):
    """玩家行动请求"""
    action_type: str = Field(..., description="行动类型: fold, call, raise, check, all_in")
    amount: Optional[int] = Field(None, description="下注金额（raise时必填）")

class PlayerActionResponse(BaseModel):
    """玩家行动响应"""
    success: bool = Field(..., description="行动是否成功")
    message: str = Field(..., description="响应消息")

class GameStateResponse(BaseModel):
    """游戏状态响应"""
    hand_id: int = Field(..., description="牌局ID")
    stage: str = Field(..., description="游戏阶段: preflop, flop, turn, river, showdown")
    board_cards: List[str] = Field(..., description="公共牌")
    pot_size: int = Field(..., description="奖池大小")
    current_bet: int = Field(..., description="当前下注额")
    to_act_user_id: Optional[int] = Field(None, description="当前行动玩家ID")
    action_deadline: Optional[datetime] = Field(None, description="行动截止时间")
    players: List[Dict] = Field(..., description="玩家状态列表")

class GameEndResponse(BaseModel):
    """游戏结束响应"""
    hand_id: int = Field(..., description="牌局ID")
    winners: List[Dict] = Field(..., description="获胜者信息")
    pot_distribution: Dict[int, int] = Field(..., description="奖池分配")
    message: str = Field(..., description="结束消息")

# WebSocket消息类型
class WSMessage(BaseModel):
    """WebSocket消息基类"""
    type: str = Field(..., description="消息类型")
    data: Dict = Field(..., description="消息数据")
    timestamp: datetime = Field(default_factory=datetime.now, description="时间戳")

class GameStartMessage(WSMessage):
    """游戏开始消息"""
    type: str = "game_start"
    
class PlayerActionMessage(WSMessage):
    """玩家行动消息"""
    type: str = "player_action"
    
class GameStateMessage(WSMessage):
    """游戏状态更新消息"""
    type: str = "game_state"
    
class GameEndMessage(WSMessage):
    """游戏结束消息"""
    type: str = "game_end"
